<template>
	<view class="read_details_box">
		<view class="content" v-if="type === '0'">
			<view class="details_title">{{ data.titleUk }}</view>
			<view class="details_image">
				<image :src="data.picture" mode="aspectFit"></image>
			</view>
			<view class="details_text">{{ data.content }}</view>
		</view>
		<view class="content" v-if="type === '1'">
			<view class="details_video">
				<video src="https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/2minute-demo.mp4"></video>
			</view>
			<view class="details_title">{{ data.title }}</view>
			
			<view class="details_text">{{ data.caption }}</view>
		</view>
		<view class="content" v-if="type === '2'">
			<view class="details_title">{{ data.title }}</view>
			<swiper class="details_swiper">
				<swiper-item v-for="(item, index) in data.content" :key="index">
					<image :src="item"></image>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
	import { detailsArticle, detailsVideo, detailsPictureBook } from '@/api/expands/readDetails/readDetails.js'
	
	export default {
		data() {
			return {
				type: '',
				data: {}
			}
		},
		onLoad(options) {
			this.type = options.type
			let title = options.type === '0' ? '英语短文' : options.type === '1' ? '英语视频' : '英语绘本'
			uni.setNavigationBarTitle({
				title
			})
			
			let id = options.id
			if (options.type === '0') {
				this.getArticle(id)
			} else if(options.type === '1') {
				this.getVideo(id)
			} else {
				this.getPictureBook(id)
			}
		},
		methods: {
			async getArticle(id) {
				const { data } = await detailsArticle(id)
				this.data = data
			},
			async getVideo(id) {
				const { data } = await detailsVideo(id)
				this.data = data
			},
			async getPictureBook(id) {
				const { data } = await detailsPictureBook(id)
				this.data = data
			}
		}
	}
</script>

<style lang="scss" scoped>
.read_details_box {
	padding: 30rpx;
	height: 100vh;
	overflow-y: auto;
	
	.content {
		.details_title {
			font-size: 48rpx;
			font-weight: bold;
			margin-bottom: 20rpx;
		}
		
		.details_image image {
			width: 100%;
			height: 420rpx;
		}
		
		.details_video video {
			width: 100%;
			height: 420rpx;
		}
		
		.details_text {
			line-height: 48rpx;
			margin-top: 20rpx;
			font-size: 32rpx;
			color: $uni-text-color;
		}
	
		.details_swiper{
			height: 75vh;
			
			image {
				width: 100%;
			}
		}
	}
	
}
</style>
